package com.jcl.elasticsearch.resume.logic;

import com.jcl.core.utils.CollectionUtils;
import com.jcl.elasticsearch.mapper.SearchResumeWorkMapper;
import com.jcl.elasticsearch.resume.model.SearchResumeEdu;
import com.jcl.elasticsearch.resume.model.SearchResumeWork;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName SearchResumeWorkLogic
 * @Description TODO
 * @Author yyliu
 * @Date 2018/11/13 10:39
 * @Version 1.0
 **/
@Component
public class SearchResumeWorkLogic implements SearchResumeWorkMapper {

    @Autowired
    SearchResumeWorkMapper searchResumeWorkMapper;

    public Map<Integer, List<SearchResumeWork>> findListByResumeMap(List<Integer> resumeIds){

        Map<Integer, List<SearchResumeWork>> dataMap = new HashMap<>();
        List<SearchResumeWork> list = searchResumeWorkMapper.findListByResumeIds(resumeIds);
        if(CollectionUtils.isNotEmpty(list)){
            for(SearchResumeWork entity: list){
                List<SearchResumeWork> entityList = dataMap.get(entity.getResumeId());
                if(null == entityList){
                    entityList = new ArrayList<>();
                    dataMap.put(entity.getResumeId(), entityList);
                }
                entityList.add(entity);
            }
        }
        return dataMap;
    }

    @Override
    public List<SearchResumeWork> findListByResumeIds(List<Integer> resumeIds) {
        return searchResumeWorkMapper.findListByResumeIds(resumeIds);
    }

    @Override
    public List<Map<String, Object>> findObjListByResumeId(Integer id) {
        return searchResumeWorkMapper.findObjListByResumeId(id);
    }

    @Override
    public List<SearchResumeWork> findListByResumeId(Integer id) {
        return searchResumeWorkMapper.findListByResumeId(id);
    }

    @Override
    public int batchInsert(List<SearchResumeWork> list) {
        return searchResumeWorkMapper.batchInsert(list);
    }

    @Override
    public int batchDeleteByResumeIds(List<Integer> ids) {
        return searchResumeWorkMapper.batchDeleteByResumeIds(ids);
    }
}
